package com.coocaa.internship.dao;

import com.coocaa.internship.pojo.UserInfo;
import com.coocaa.internship.dao.provider.UserInfoSqlProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

/**
 * @Description: 用户信息Dao层
 * @Author: zwh
 * @Date: 2019-07-25
 * @Time: 19:07
 */
@Mapper
@Component
public interface UserInfoDao {
    String TABLE_NAME = "user_info";
    String SELECT_FILEDS = "user_id , user_info_avatar , user_info_name , user_info_email , user_info_phone , user_info_school , user_info_gradtime , user_info_major";
    String INSERT_FILEDS = "user_id , user_info_avatar , user_info_name , user_info_email , user_info_phone , user_info_school , user_info_gradtime , user_info_major";

    @Select({"select ",SELECT_FILEDS," from ",TABLE_NAME," where user_id = #{userId}"})
    UserInfo selectUserInfoById(@Param("userId") Long userId);

    @Insert({"insert into ",TABLE_NAME," (",INSERT_FILEDS,") values ( #{userId} , #{userInfoAvatar} , #{userInfoName} , #{userInfoEmail} " +
            ", #{userInfoPhone} , #{userInfoSchool} , #{userInfoGradtime} , #{userInfoMajor})"})
    Integer insertUserInfo(UserInfo userInfo);

    @UpdateProvider(type = UserInfoSqlProvider.class,method = "updateUserInfoById")
    Integer updateUserInfoById(UserInfo userInfo);

    @Delete({"delete from ", TABLE_NAME, " where user_id = #{userId}"})
    Integer deleteUserInfoById(@Param("userId") Long userId);
}
